var app = getApp();
var menus = [{
  icon: "http://file.xiaomutong.com.cn/rank.png",
  title: "成绩排名",
  msg: "",
  showRight: 1
},{
  icon: "https://bmob-cdn-24471.bmobcloud.com/2019/07/11/e2c738a74048b4fa801ccf82800a8c8e.png",
  title: "我的成绩",
  msg: "",
  showRight: 1
},{
  icon: "http://picture.eclicks.cn/kaojiazhao/public/wx_xcx/center/icon/icon_center_tj.png",
  title: "分享好友",
  msg: "",
  showRight: 1
},{
  icon: "http://picture.eclicks.cn/kaojiazhao/public/wx_xcx/center/icon/icon_center_download.png",
  title: "关于我们",
  msg: "",
  showRight: 1
},{
  icon: "http://picture.eclicks.cn/kaojiazhao/public/wx_xcx/center/icon/icon_center_download.png",
  title: "发布试卷",
  msg: "",
  showRight: 1
},{
  icon: "http://picture.eclicks.cn/kaojiazhao/public/wx_xcx/center/icon/icon_center_download.png",
  title: "发布试题",
  msg: "",
  showRight: 1
},{
  icon: "http://picture.eclicks.cn/kaojiazhao/public/wx_xcx/center/icon/icon_center_download.png",
  title: "删除试卷",
  msg: "",
  showRight: 1
}];


Page({
  data: {
    show: false,
    menus: menus,
    userInfo: {},
  },

  onShow: function () {
    this.onQuery();
    var that = this;
    wx.getUserInfo({
      success: function (res) {
        that.setData({
          userInfo: {
            nickName: res.userInfo.nickName,
            avatarUrl: res.userInfo.avatarUrl || "https://picture.eclicks.cn/kaojiazhao/public/wx_xcx/default/gungun.png"
          }
        })
      }
    });
  },
  go_view: function (e) {
    switch (1 * e.currentTarget.dataset.viewind) {
      case 0:
        wx.navigateTo({
          url: '../item/item?mode=1',
        })
        break;
      case 1:
        wx.navigateTo({
          url: '../item/item?mode=2',
        })
        break;
      case 2:
        break;
      case 3:
        wx.navigateTo({
          url: '../about/about',
        })
        break;
      case 4:
        wx.navigateTo({
          url: '../fabu/fabu',
        })
        break;
      case 5:
        wx.navigateTo({
          url: '../select/select',
        })
        break;   
      case 6:
          wx.navigateTo({
            url: '../delete/delete',
          })
          break;                          
    }
  },
  about() {
    wx.showModal({
      title: '关于我们',
      content: '本程序仅供考试学习使用，请勿使用于商业用途，如有问题，请联系微信：15692121959。',
      showCancel: false
    })
  },
  onLoad: function (options) {

    

  },
  onQuery: function() {
    let that = this;

    const db = wx.cloud.database()
    db.collection('teachers').doc('20200418')
    .get().then(res => {
      // res.data 包含该记录的数据
      console.log('[数据库] [查询记录] 成功: ', res)
      let items = res.data.items;
      let newMenus = menus.concat()
      if(items.indexOf(app.globalData.openid) == -1){
        newMenus.pop();
        newMenus.pop();
        newMenus.pop();
      }
      this.setData({
        menus: newMenus
      })

    })
  },
  onShareAppMessage: function () {
    return {
      title: "小二上题，不服来战！",
      path: "pages/start/start",
      imageUrl: "http://file.xiaomutong.com.cn/20200211/share.png"
    };
  }
});